/*
 * Transfer.h
 *
 *  Created on: 2.4.2011
 *      Author: Tomas Srna
 */

#ifndef TRANSFER_H_
#define TRANSFER_H_

#define BLOCK_SIZE 512

#include <iostream>
#include <ctime>
#include <cstdlib>
#include "Packet.h"
#include "IFile.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <cstring>
#include <map>

class Transfer {
protected:
	unsigned int local_port;
	unsigned int remote_port;
	unsigned int last_ack;
	time_t last_packet;
	std::string filename;
	std::string mode;
	std::ostream& logger;
	IFile& fs;
	int sock;
	struct sockaddr_in server;
	struct sockaddr_in client;
public:
	Transfer(struct sockaddr_in client, IFile& fs, std::string fn,
			std::string m, std::ostream& logr = std::cout);
	virtual void run() = 0;
	virtual ~Transfer();
	static void* proc(Transfer* t);
	virtual std::string type() const = 0;
	void snd(const Packet& p);
	friend std::ostream& operator << (std::ostream& os, const Transfer& tr);
};

#endif /* TRANSFER_H_ */
